package com.xyq.test;

import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

import java.time.Duration;

public class Utils {
    WebDriver driver ;

    void create(){
        WebDriverManager.chromedriver().setup();
        ChromeOptions options = new ChromeOptions() ;

        options.addArguments("--remote-allow-origins=*") ;

        driver = new ChromeDriver(options);
        driver.get("https://www.saucedemo.com/inventory.html");
        // 隐式等待
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(2)) ;
    }
   void login() throws InterruptedException {
        create();

        driver.findElement(By.cssSelector("#user-name")).sendKeys("standard_user");
        driver.findElement(By.cssSelector("#password")).sendKeys("secret_sauce");

        driver.findElement(By.cssSelector("#login-button")) .click();

   }

   void list() throws InterruptedException {
        login();
        // 查看标签判断
        driver.findElement(By.cssSelector("#header_container > div.primary_header > div.header_label > div"));


   }
   void details() throws InterruptedException {
        login();
      // 点击查看 商品详情
       driver.findElement(By.cssSelector("#item_0_img_link > img")).click();

    }

    void add() throws InterruptedException {
        details();
       // 添加商品到购物车
        driver.findElement(By.cssSelector("#add-to-cart")).click();

    }
    void delete() throws InterruptedException {
        add();
        // 删除商品
        driver.findElement(By.cssSelector("#remove")).click();

    }
   void jiaoyi() throws InterruptedException {
        add();
       // 填写结算信息

       driver.findElement(By.cssSelector("#shopping_cart_container > a")).click();
       driver.findElement(By.cssSelector("#checkout")).click();

       driver.findElement(By.cssSelector("#first-name")).sendKeys("测试");
       driver.findElement(By.cssSelector("#last-name")).sendKeys("测试");

       driver.findElement(By.cssSelector("#continue")).click();

   }
}
